package collection

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"ppa/model"
)

// GetCollectionInfo
// @Summary 获取合集信息
// @Tags 合集详情操作
// @Produce  json
// @Description 请输入正确的合集地址或者短标识等
// @Param collection_address query string false "collection_address"
// @Param short_url query string false "short_url"
// @Param token_symbol query string false "token_symbol"
// @Success 200   {object} model.Collection
// @Router /collection/info [get]
func GetCollectionInfo(c *gin.Context) {
	var collection model.Collection
	if err := c.ShouldBind(&collection);err != nil{
		c.JSON(http.StatusBadRequest,gin.H{"message":err.Error()})
		return
	}
	resData,err:= collection.GetCollectionInfo()
	if err != nil {
		c.JSON(http.StatusLengthRequired,gin.H{"message":err.Error()})
		return
	}
	c.JSON(http.StatusOK,gin.H{"data":resData})
	return
}

// SetCollectionInfo
// @Summary 创建合集(别找了没有更新合集)
// @Tags 合集详情操作
// @Produce  json
// @Description 创建合集 请确保地址 不重复 短地址不重复
// @Param collection_images query string true "collection_images"
// @Param collection_name query string true "collection_name"
// @Param collection_address query string true "collection_address"
// @Param user_id query int true "user_id"
// @Param short_url query string true "short_url"
// @Param token_symbol query string true "token_symbol"
// @Router /collection/info [post]
func SetCollectionInfo(c *gin.Context) {
	var collection model.Collection
	if err := c.ShouldBind(&collection);err != nil{
		c.JSON(http.StatusBadRequest,gin.H{"message":err.Error()})
		return
	}
	fmt.Println(collection)
	_, err := collection.SetCollectionInfo()
	if err != nil {
		c.JSON(http.StatusLengthRequired,gin.H{"message":err.Error()})
		return
	}
	c.JSON(http.StatusOK,gin.H{"message":"插入成功"})
	return
}